/*
   Chris
   Made By ups2000ups
*/

void npc(Player @player, NPC @npc) {
	int state = npc.getState();
	int type = npc.getSelected();
	npc.setVariable("type", type);

	string [] menu		= {"Refine the ores of a mineral", "Refine the ores of a jewel", "I have Iron Hog's Metal Hoof", "I want to upgrade a Claw"};

	int [] midID		= {0000000, 0000000, 0};

	int [] mineral 		= {8, 4011000, 4011001, 4011002, 4011003, 4011004, 4011005, 4011006};
	int [] _Bronze  	= {4011000, 4010000, 250};
	int [] _Steel		= {4011001, 4010001, 250};
	int [] _Mithril 	= {4011002, 4010002, 250};
	int [] _Adamant 	= {4011003, 4010003, 450};
	int [] _Silver  	= {4011004, 4010004, 450};
	int [] _Orihalcon  	= {4011005, 4010005, 450};
	int [] _Gold	  	= {4011006, 4010006, 750};

	int [] jewel   		= {10, 4021000, 4021001, 4021002, 4021003, 4021004, 4021005, 4021006, 4021007, 4021008};
	int [] _Garnet		= {4021000, 4020000 ,450};
	int [] _Amethyst	= {4021001, 4020001 ,450};
	int [] _AquaMarine	= {4021002, 4020002 ,450};
	int [] _Emerald		= {4021003, 4020003 ,450};
	int [] _Opal		= {4021004, 4020004 ,450};
	int [] _Sapphire	= {4021005, 4020005 ,450};
	int [] _Topaz		= {4021006, 4020006 ,450};
	int [] _Diamond		= {4021007, 4020007 ,950};
	int [] _BlackCrystal	= {4021008, 4020008, 2900};


	int [] _temp				= {0,0,0,0,0,0,0,0};
	int [] _tempinfo			= {0,0,0,0,0,0,0,0};

	// Uppgrade
	int [] upgrade		= {4, 1472023, 1472024, 1472025};
	string [] upgradeinfo	= {"empty", "(level limit : 60, thief)", "(level limit : 60, thief)", "(level limit : 60, thief)"};

	int [] _BloodGigantic 			= {7, 1472022, 4011007, 4021000, 2012000, 80000, 1472023};
	int [] _BloodGiganticinfo 		= {0, 1      , 1      , 8      , 10     , 0    , 999};
	int [] _SapphireGigantic		= {7, 1472022, 4011007, 4021005, 2012002, 80000, 1472024};
	int [] _SapphireGiganticinfo 		= {0, 1      , 1      , 8      , 10     , 0    , 999};
	int [] _DarkGigantic			= {7, 1472022, 4011007, 4021008, 4000046, 100000, 1472025};
	int [] _DarkGiganticinfo 		= {0, 1      , 1      , 3      , 5      , 0     , 999};


	if(state == 0){
		npc.addText("What's up? Do you have, by any chance, the raw ore of a mineral or a jewel? With a little service fee i can turn them into a useful material for a weapon or an armor. I learned how to refine while working on fixing items... what do you think? wanna let me do it?");
		npc.sendYesNo();
	}
	else if(state == 1){
		if(npc.getSelected() == YES){
			npc.addText("OK! with the ore and a little service fee, I can refine it so you can use it. Before that please make sure you have an empty slot avible at the etc inventory. Now... what do you want me to do?#b\r\n#L0#" + menu[0] + "#l\r\n#L1#" + menu[1] + "#l\r\n#L2#" + menu[2] + "#l\r\n#L3#" + menu[3] + "#l#k");
			npc.sendSimple();

		}
		else if(npc.getSelected() == NO){
			npc.addText("I see... but I am sure one dat you'll need my help... and when that day comes, then please come back to me alright?");
			npc.sendNext();
			npc.end();
		}
	}

	else if(state == 2) {
		if(type == 0) {
			npc.addText("What kind of mineral do you want to make?");

			for(int x = 1; x < mineral[0]; x++){
				npc.addText("#b\r\n#L" + (x-1) + "##t" + mineral[x] + "##l#k");
			}
			npc.setState(9);
			npc.sendSimple();
		}
		else if(type == 1) {
			npc.addText("What kind of jewel do you want to refine");

			for(int x = 1; x < jewel[0]; x++){
				npc.addText("#b\r\n#L" + (x-1) + "##t" + jewel[x] + "##l#k");
			}
			npc.setState(19);
			npc.sendSimple();
		}
		else if(type == 2) {
			npc.addText("You have #bIron Hog's Metal Hoof#k? Hmmm... With that I can try making Steel Plate. If you give me #b100 Iron Hog's Metal Hoofs#k and #b1000 mesos#k, I can make you a #brefined Steel Plate#k. What do you think? Do you want to try it?");
			npc.setState(29);
			npc.sendYesNo();
		}
		else if(type == 3){
			npc.addText("So you want to upgrade the Claw? OK, then. A word of warning, thought: All the items that will be used for upgrading will be gone, and if you use an item that has been #rupgraded#k with a scroll before, the effect will not go in when upgraded. Please take that into consideration when making the decision, OK?");
			npc.setState(39);
			npc.sendNext();
		}
	}

// ------------------ upgrade
	else if(state == 40){
		npc.addText("Now... what kind of the Claw do you want to upgrade?");
		for(int x = 1; x < upgrade[0]; x++){
			npc.addText("#b\r\n#L" + (x-1) + "##t" + upgrade[x] + "##k " + upgradeinfo[x] + "#l");
		}
		npc.sendSimple();


	}
	else if(state == 41){
		npc.setGetSaveInt(type);
		
		if(npc.getSaveInt() == 0){
			_temp = _BloodGigantic;
			_tempinfo = _BloodGiganticinfo;
		}
		else if(npc.getSaveInt() == 1){
			_temp = _SapphireGigantic;
			_tempinfo = _SapphireGiganticinfo;
		}
		else if(npc.getSaveInt() == 2){
			_temp = _DarkGigantic;
			_tempinfo = _DarkGiganticinfo;
		}

		npc.addText("Do you want to upgrade #t" +  _temp[_temp[0]-1] + "#, I need the following items. Note please make sure you don't use an item that's been upgraded as a material for it. What do you think? Do you want one?");


		for(int i = 1; i < _temp[0]; i++){
			if(_tempinfo[i] == 0){
				npc.addText("#b\r\n#v4031138# " + _temp[i] + " Mesos #k");
			}
			else if(_tempinfo[i] == 999){
				// nothing right now just to not show is as payment
			}
			else if(_tempinfo[i] > 1){
				npc.addText("#b\r\n#v" + _temp[i] + "# " + + _tempinfo[i] + " #t" + _temp[i] + "##k");
			}
			else {
				npc.addText("#b\r\n#v" + _temp[i] + "#  #t" + _temp[i] + "##k");
			}
		} 
		npc.sendYesNo();
	}

	else if(state == 42) {
		if(npc.getSaveInt() == 0){
			_temp = _BloodGigantic;
			_tempinfo = _BloodGiganticinfo;
		}
		else if(npc.getSaveInt() == 1){
			_temp = _SapphireGigantic;
			_tempinfo = _SapphireGiganticinfo;
		}
		else if(npc.getSaveInt() == 2){
			_temp = _DarkGigantic;
			_tempinfo = _DarkGiganticinfo;
		}

		if(npc.getSelected() == YES){

			type = 0;

			for(int x = 1; x < _temp[0]; x++){

				if(_tempinfo[x] == 0){
					if(player.getMesos() < _temp[x]){
						type = 1;
					}
				}
				else if(_tempinfo[x] == 999){
					// nothing just to skip it for now
				}
				else {
					if(player.getItemAmount(_temp[x]) < _tempinfo[x]){
						type = 1;
					}
				}
			}

			if(type == 0){
				for(int x = 1; x < _temp[0]; x++){

					if(_tempinfo[x] == 0){
						player.giveMesos(-_temp[x]);
					}
					else if(_tempinfo[x] == 999){
						player.giveItem(_temp[x], 1);
					}
					else {
						player.giveItem(_temp[x], -_tempinfo[x]);
					}
				}

				npc.addText("Did it turn out ok? Well it looks like it did! Come back if you want to upgrade something else.");
				npc.sendNext();
				npc.end();
			}
			else if (type == 1){
				npc.addText("Check and see if you have everything you need and if your equipment inventory may be full or not");
				npc.sendNext();
				npc.end();
			}
		}
		else if(npc.getSelected() == NO){
			npc.addText("Lacking the materials? it's ok... Collect them all and then come find me, alright? I'll be waiting...");
			npc.sendNext();
			npc.end();
		}

	}


//---------------------------------------- Minerals --------------------------------
	else if(state == 10) {
		npc.setGetSaveInt(type);

		if(npc.getSaveInt() == 0){
			midID = _Bronze;
		}
		else if(npc.getSaveInt() == 1){
			midID = _Steel;
		}
		else if(npc.getSaveInt() == 2){
			midID = _Mithril;
		}
		else if(npc.getSaveInt() == 3){
			midID = _Adamant;
		}
		else if(npc.getSaveInt() == 4){
			midID = _Silver;
		}
		else if(npc.getSaveInt() == 5){
			midID = _Orihalcon;
		}
		else if(npc.getSaveInt() == 6){
			midID = _Gold;
		}
		npc.addText("Do you want to make a(n) #t" + midID[0] + "#? To do that, you'll need the materials below. How many would you like to make?");
		npc.addText("#b\r\n#v" + midID[1] + "# 10 #t" + midID[1] + "##k");
		npc.addText("#b\r\n#v4031138# " + midID[2] + " Mesos #k");
		npc.sendGetNumber(0,0,100);
	}

	else if(state == 11){
		if(npc.getSaveInt() == 0){             // added again since angelscript sux ? :D
			midID = _Bronze;
		}
		else if(npc.getSaveInt() == 1){
			midID = _Steel;
		}
		else if(npc.getSaveInt() == 2){
			midID = _Mithril;
		}
		else if(npc.getSaveInt() == 3){
			midID = _Adamant;
		}
		else if(npc.getSaveInt() == 4){
			midID = _Silver;
		}
		else if(npc.getSaveInt() == 5){
			midID = _Orihalcon;
		}
		else if(npc.getSaveInt() == 6){
			midID = _Gold;
		}

		npc.addText("To make #b" + npc.getNumber() + " #t" + midID[0] + "(s)##k,you'll need the materials listed below. Do you really want to make it?");
		npc.addText("#b\r\n#v" + midID[1] + "# " + (npc.getNumber()*10) + " #t" + midID[1] + "##k");
		npc.addText("#b\r\n#v4031138# " + (npc.getNumber()*midID[2]) + " Mesos #k");
		npc.sendYesNo();
	}

	else if(state == 12){
		if(npc.getSaveInt() == 0){             // added again since angelscript sux ? :D
			midID = _Bronze;
		}
		else if(npc.getSaveInt() == 1){
			midID = _Steel;
		}
		else if(npc.getSaveInt() == 2){
			midID = _Mithril;
		}
		else if(npc.getSaveInt() == 3){
			midID = _Adamant;
		}
		else if(npc.getSaveInt() == 4){
			midID = _Silver;
		}
		else if(npc.getSaveInt() == 5){
			midID = _Orihalcon;
		}
		else if(npc.getSaveInt() == 6){
			midID = _Gold;
		}

		if(npc.getSelected() == YES){
			if((player.getItemAmount(midID[1]) >= 10) && (player.getMesos() >= midID[2])) {
				player.giveItem(midID[1], -(10*npc.getNumber()));
				player.giveMesos(-(midID[2]*npc.getNumber()));
				player.giveItem(midID[0], npc.getNumber());
				npc.addText("Hey! Here, take " + npc.getNumber() + " #t" + midID[0] + "#(s). This came out even finder than I thought... a finely refined item like this, I dont't think you'll see it anywhere else!! Pleaset come again~");
				npc.sendOK();
				npc.end();
			}
			else{
				npc.addText("Please double-check you have all the materials you need and if your etc inventory may be full or not.");
				npc.sendNext();
				npc.end();
			}

		}
		else if(npc.getSelected() == NO){
			npc.addText("I can refine other materials and jewels, so take your time and think about it, ok?");
			npc.sendNext();
			npc.end();
		}
	}


//---------------------------------------- Jewel --------------------------------
	else if(state == 20) {
		npc.setGetSaveInt(type);

		if(npc.getSaveInt() == 0){
			midID = _Garnet;
		}
		else if(npc.getSaveInt() == 1){
			midID = _Amethyst;
		}
		else if(npc.getSaveInt() == 2){
			midID = _AquaMarine;
		}
		else if(npc.getSaveInt() == 3){
			midID = _Emerald;
		}
		else if(npc.getSaveInt() == 4){
			midID = _Opal;
		}
		else if(npc.getSaveInt() == 5){
			midID = _Sapphire;
		}
		else if(npc.getSaveInt() == 6){
			midID = _Topaz;
		}
		else if(npc.getSaveInt() == 7){
			midID = _Diamond;
		}
		else if(npc.getSaveInt() == 8){
			midID = _BlackCrystal;
		}
		npc.addText("Do you want to make a(n) #t" + midID[0] + "#? To do that, you'll need the materials below. How many would you like to make?");
		npc.addText("#b\r\n#v" + midID[1] + "# 10 #t" + midID[1] + "##k");
		npc.addText("#b\r\n#v4031138# " + midID[2] + " Mesos #k");
		npc.sendGetNumber(0,0,100);
	}

	else if(state == 21){
		if(npc.getSaveInt() == 0){
			midID = _Garnet;
		}
		else if(npc.getSaveInt() == 1){
			midID = _Amethyst;
		}
		else if(npc.getSaveInt() == 2){
			midID = _AquaMarine;
		}
		else if(npc.getSaveInt() == 3){
			midID = _Emerald;
		}
		else if(npc.getSaveInt() == 4){
			midID = _Opal;
		}
		else if(npc.getSaveInt() == 5){
			midID = _Sapphire;
		}
		else if(npc.getSaveInt() == 6){
			midID = _Topaz;
		}
		else if(npc.getSaveInt() == 7){
			midID = _Diamond;
		}
		else if(npc.getSaveInt() == 8){
			midID = _BlackCrystal;
		}

		npc.addText("To make #b" + npc.getNumber() + " #t" + midID[0] + "(s)##k,you'll need the materials listed below. Do you really want to make it?");
		npc.addText("#b\r\n#v" + midID[1] + "# " + (npc.getNumber()*10) + " #t" + midID[1] + "##k");
		npc.addText("#b\r\n#v4031138# " + (npc.getNumber()*midID[2]) + " Mesos #k");
		npc.sendYesNo();
	}

	else if(state == 22){
		if(npc.getSaveInt() == 0){
			midID = _Garnet;
		}
		else if(npc.getSaveInt() == 1){
			midID = _Amethyst;
		}
		else if(npc.getSaveInt() == 2){
			midID = _AquaMarine;
		}
		else if(npc.getSaveInt() == 3){
			midID = _Emerald;
		}
		else if(npc.getSaveInt() == 4){
			midID = _Opal;
		}
		else if(npc.getSaveInt() == 5){
			midID = _Sapphire;
		}
		else if(npc.getSaveInt() == 6){
			midID = _Topaz;
		}
		else if(npc.getSaveInt() == 7){
			midID = _Diamond;
		}
		else if(npc.getSaveInt() == 8){
			midID = _BlackCrystal;
		}

		if(npc.getSelected() == YES){
			if((player.getItemAmount(midID[1]) >= 10) && (player.getMesos() >= midID[2])) {
				player.giveItem(midID[1], -(10*npc.getNumber()));
				player.giveMesos(-(midID[2]*npc.getNumber()));
				player.giveItem(midID[0], npc.getNumber());
				npc.addText("Hey! Here, take " + npc.getNumber() + " #t" + midID[0] + "#(s). This came out even finder than I thought... a finely refined item like this, I dont't think you'll see it anywhere else!! Pleaset come again~");
				npc.sendOK();
				npc.end();
			}
			else{
				npc.addText("Please double-check you have all the materials you need and if your etc inventory may be full or not.");
				npc.sendNext();
				npc.end();
			}

		}
		else if(npc.getSelected() == NO){
			npc.addText("I can refine other materials and jewels, so take your time and think about it, ok?");
			npc.sendNext();
			npc.end();
		}
	}

//-------------------------------------------------------
	else if(state == 30){
		if(npc.getSelected() == YES){
			if((player.getItemAmount(4000039) >= 100) && (player.getMesos() >= 1000)){
				npc.addText("Here you go. Come back if you want to refine more meterials");
				player.giveItem(4000039, -100);
				player.giveMesos(-1000);
				player.giveItem(4011001, 1);	
			}
			else{
				npc.addText("Maybe you are lacking some money... please check and see if you have 100 Iron Hog's Metal Hoofs and 1000 mesos, along with a free slot at the etc inventory.");
				npc.sendNext();
				npc.end();
			}
		}
		else if(npc.getSelected() == NO){
			npc.addText("I can refine other materials and jewels, so take your time and think about it, ok?");
			npc.sendNext();
			npc.end();
		}
	}
}